﻿@model BbsAdminEditModel
@{
    ResLink.AddCss("~/res/css/bbs/admin.css");
}

<h1>게시판 관리</h1>
<hr />

<form id="제목폼" class="form-inline">
    <h2>게시판 제목:</h2>
    @Html.TextBox("title", Model.게시판.제목, new { data_lsj_validate = "required" })
    @Html.Hidden("id", Model.게시판.ID)
    <a onclick="게시판제목저장()" class="btn btn-small">제목 저장</a>
</form> 

<h2>게시글 분류:</h2>
<table class="table table-condensed table-bordered">
    <thead>
        <tr>
            <th>no</th>
            <th>제목</th>
        </tr>
    </thead>
    <tbody>
        @{ int no = 0; }
        @foreach(var 분류 in Model.게시글분류목록) { 
            <tr>
                <td>@(++no)</td>
                <td>
                    <form>
                        <input type="hidden" name="id" value="@분류.ID" />
                        <input type="text" name="title" value="@분류.제목" />
                        <a class="btn btn-small" onclick="게시글분류저장(this)"><i class="icon-pencil"></i> 저장</a>
                        <a class="btn btn-small" onclick="게시글분류삭제(this)"><i class="icon-remove"></i> 삭제</a>
                    </form>
                </td>
            </tr>
        }
        <tr>
            <td></td>
            <td>
                <form>
                    <input type="hidden" name="id" value="@Model.게시판.ID" />
                    <input name="title" type="text" />
                    <a class="btn btn-small" onclick="게시글분류추가(this)"><i class="icon-plus"></i> 추가 </a>
                </form>
            </td>
        </tr>
    </tbody>
</table>


<hr />
<a onclick="새게시판생성()" class="btn btn-primary"><i class="icon-plus icon-white"></i> 게시판 생성</a>
<a onclick="게시판삭제(@Model.게시판.ID)" class="btn"><i class="icon-remove"></i> 게시판 삭제</a>
<a href="@Url.BbsList(Model.게시판.ID)" class="btn"><i class="icon-list"></i> 게시글 목록으로</a>

<script type="text/javascript">
    function 게시판제목저장() {
        AjaxPostForm($("form#제목폼"), '@Url.MyAction("UpdateTitle", "BbsAdmin")');
    }

    function 게시글분류저장(button) {
        AjaxPostForm($(button).parents('form'), '@Url.MyAction("UpdateCategory", "BbsAdmin")');
    }

    function 게시글분류삭제(button) {
        AjaxPostForm($(button).parents('form'), '@Url.MyAction("DeleteCategory", "BbsAdmin")', "삭제하시겠습니까?");
    }

    function 게시글분류추가(button) {
        AjaxPostForm($(button).parents('form'), '@Url.MyAction("AddCategory", "BbsAdmin")');
    }

    function 새게시판생성() {
        AjaxPost('@Url.MyAction("New", "BbsAdmin")', null, "게시판을 생성하시겠습니까?");
    }

    function 게시판삭제(id) {
        AjaxPost('@Url.MyAction("Delete", "BbsAdmin")', { id: id }, "삭제하시겠습니까?");
    }
</script>